/**
 * CS543 HW4 Joseph Meyer
 */
package edu.src.paging;

/**
 * A respose from the PageTable
 * Contains all the items we care about
 * 
 * @author meyer
 */
public class PageResult {

	private int frame;
	private int offset;
	private byte value;
	private int physicalAddress;
	private int logicalAddress;
	
	/**
	 * Emptry constructor.
	 */
	public PageResult() {
	}
	
	/**
	 * Parameterized Constructor
	 */
	public PageResult(int frame, int offset, byte value, int pAdd, int lAdd) {
		this.frame = frame;
		this.offset = offset;
		this.value = value;
		this.physicalAddress = pAdd;
		this.logicalAddress = lAdd;
	}
	
	
	/**
	 * @return the frame
	 */
	public int getFrame() {
		return frame;
	}

	/**
	 * @param frame the frame to set
	 */
	public void setFrame(int frame) {
		this.frame = frame;
	}

	/**
	 * @return the offset
	 */
	public int getOffset() {
		return offset;
	}

	/**
	 * @param offset the offset to set
	 */
	public void setOffset(int offset) {
		this.offset = offset;
	}

	/**
	 * @return the value
	 */
	public byte getValue() {
		return value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(byte value) {
		this.value = value;
	}

	/**
	 * @return the physicalAddress
	 */
	public int getPhysicalAddress() {
		return physicalAddress;
	}
	
	/**
	 * @param physicalAddress the physicalAddress to set
	 */
	public void setPhysicalAddress(int physicalAddress) {
		this.physicalAddress = physicalAddress;
	}

	/**
	 * @return the logicalAddress
	 */
	public int getLogicalAddress() {
		return logicalAddress;
	}

	/**
	 * @param logicalAddress the logicalAddress to set
	 */
	public void setLogicalAddress(int logicalAddress) {
		this.logicalAddress = logicalAddress;
	}

	/**
	 * Was going to implment a comparable, but this is more what I want.
	 * returns true if all the following are equal:
	 * 	this.frame = frame;
		this.offset = offset;
		this.value = value;
		this.physicalAddress = pAdd;
		this.logicalAddress = lAdd;
		
	 * @param o
	 * @return boolean true if equal
	 */
	public boolean compareTo(PageResult o) {
		if (this.frame == o.getFrame()) {
			if (this.offset == o.getOffset()) {
				if (this.value == o.getValue()) {
					if (this.physicalAddress == o.getPhysicalAddress()) {
						if (this.logicalAddress == o.getLogicalAddress()) {
							return true;
						}
					}
				}
			}
		}
		return false;
	}
	
	public String formattedOutput() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("Virtual address: ");
		sb.append(logicalAddress);
		sb.append(" Physical address: ");
		sb.append(physicalAddress);
		sb.append(" Value: ");
		sb.append(value);
		sb.append("\n");
		
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "PageResult [frame=" + frame + ", offset=" + offset + ", value="
				+ value + ", physicalAddress=" + physicalAddress
				+ ", logicalAddress=" + logicalAddress + "]";
	}

}
